#include "../src/biTree/biTree.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

extern func_BiTree fBiTree;

int main(int argc, const char *argv[])
{
    int ret = 0;
    printf("请按照先序输入二叉树(空用#表示)：");
    BiTNode *tree = fBiTree.create();
    if (tree != NULL)
    {
        printf("二叉树创建成功！\n");
    }
    else
    {
        printf("二叉树创建出现异常！\n");
        ret = -1;
        goto ERROR_END;
    }
    printf("先序遍历输出：");
    fBiTree.prevOrder(tree);
    putchar(10);

    printf("中序遍历输出：");
    fBiTree.inOrder(tree);
    putchar(10);

    printf("后序遍历输出：");
    fBiTree.postOrder(tree);
    putchar(10);

    printf("层序遍历输出：");
    fBiTree.levelOrder(tree);
    putchar(10);

    int leaf = 0;
    fBiTree.leafNum(tree, &leaf);
    printf("树的叶子节点的个数为：%d\n", leaf);

    int depth = fBiTree.depth(tree);
    printf("树的深度/高度为：%d\n", depth);

    int degree = fBiTree.degree(tree);
    printf("树的度为：%d\n", degree);

    BiTNode *copyTree = fBiTree.copy(tree);
    printf("copy树的先序遍历输出：");
    fBiTree.prevOrder(copyTree);
    putchar(10);

    printf("copy树的中序遍历输出：");
    fBiTree.inOrder(copyTree);
    putchar(10);

    printf("copy树的后序遍历输出：");
    fBiTree.postOrder(copyTree);
    putchar(10);

    printf("copy树的层序遍历输出：");
    fBiTree.levelOrder(copyTree);
    putchar(10);

ERROR_END:
    // 释放二叉树
    fBiTree.release(tree);
    // 释放二叉树
    fBiTree.release(copyTree);

    printf("system exit with return code %d\n", ret);

    return 0;
}
